package com.wings4.security

import com.wings4.security.utils.EncryptionUtils



class Authority {
    Integer id
    String roleTitle
    String description
    //Authority parentKey

    static hasMany = [features : Feature, users : User, userGroups : UserGroup]

    static belongsTo = [User, UserGroup];


    static constraints = {
        roleTitle(blank:false,size:1..30,unique:true)
    }

    String toString(){
        return roleTitle
    }

    public static void initialize(){
        EncryptionUtils encUtil = new EncryptionUtils("wings4");
        def defaultAuthority = new Authority(
                roleTitle: "gen_admin",
                description: "general admin"
        )
        def defaultUser = new User(
                userCode: "admin",
                password: encUtil.encrypt("asadmin"),
                active: true
        )
        defaultUser.addToAuthorities(defaultAuthority).save(flush: true);

    }
}
